package biz.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "bbs_user")
public class BbsUser implements Serializable {

	private static final long serialVersionUID = 1L;
	private String id;
	private String username;
	private String password;
	private String nickname;
	private String email;
	private String sex;
	private String birthyear;
	private String birthmonth;
	private String birthday;
	private Timestamp registertime;
	private int deleteflag;
	private Timestamp deletedate;
	private String portrait;
	private String portraitpath;
	private int usergrade;
	private List<BbsBoard> boardlist;
	private List<BbsPost> postlist;
	private List<BbsAttachment> attlist;
	
	@Id
	@GeneratedValue(generator = "pk")
	@GenericGenerator(name = "pk", strategy = "uuid.hex")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getBirthyear() {
		return birthyear;
	}

	public void setBirthyear(String birthyear) {
		this.birthyear = birthyear;
	}

	public String getBirthmonth() {
		return birthmonth;
	}

	public void setBirthmonth(String birthmonth) {
		this.birthmonth = birthmonth;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public Timestamp getRegistertime() {
		return registertime;
	}

	public void setRegistertime(Timestamp registertime) {
		this.registertime = registertime;
	}

	public int getDeleteflag() {
		return deleteflag;
	}

	public void setDeleteflag(int deleteflag) {
		this.deleteflag = deleteflag;
	}

	public Timestamp getDeletedate() {
		return deletedate;
	}

	public void setDeletedate(Timestamp deletedate) {
		this.deletedate = deletedate;
	}

	public String getPortrait() {
		return portrait;
	}

	public void setPortrait(String portrait) {
		this.portrait = portrait;
	}

	public String getPortraitpath() {
		return portraitpath;
	}

	public void setPortraitpath(String portraitpath) {
		this.portraitpath = portraitpath;
	}

	public int getUsergrade() {
		return usergrade;
	}

	public void setUsergrade(int usergrade) {
		this.usergrade = usergrade;
	}

	@OneToMany(mappedBy="boarduser", cascade = CascadeType.REFRESH)
	public List<BbsBoard> getBoardlist() {
		return boardlist;
	}

	public void setBoardlist(List<BbsBoard> boardlist) {
		this.boardlist = boardlist;
	}

	@OneToMany(mappedBy="postuser", cascade = CascadeType.REFRESH)
	public List<BbsPost> getPostlist() {
		return postlist;
	}

	public void setPostlist(List<BbsPost> postlist) {
		this.postlist = postlist;
	}

	@OneToMany(mappedBy="attuser", cascade = CascadeType.REFRESH)
	public List<BbsAttachment> getAttlist() {
		return attlist;
	}

	public void setAttlist(List<BbsAttachment> attlist) {
		this.attlist = attlist;
	}

	public int hashCode()
	{
		return new HashCodeBuilder().append(getId()).toHashCode();
	}

	public String toString()
	{
		return new ToStringBuilder(this).append("id", getId()).toString();
	}

	public boolean equals(Object other)
	{
		if (this == other)
		{
			return true;
		}
		if (!(other instanceof BbsUser))
		{
			return false;
		}
		BbsUser castOther = (BbsUser) other;
		return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
	}

}
